package com.bootcamp.servlet.mvc.controller;

/**
 * @program: wrok-1101
 * @author: Keyu Li
 * @create: 2021-11-08 13:54
 **/

import com.bootcamp.servlet.mvc.utils.CartUtils;
import com.bootcamp.servlet.mvc.utils.StoreUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "StoreServlet", value = "/store/*")
public class StoreServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String op = request.getRequestURI().replace(request.getContextPath()+"/store/","");
        if ("page".equals(op)){
            // 展示所有商品
            StoreUtils.printStoreProducts(request,response);
        }
        else if ("addcart".equals(op)){
            // 添加购物车
            CartUtils.addCartItem(request,response);
        }
        else if("detail".equals(op)){
            // 展示商品细节
            StoreUtils.printProductDetails(request,response);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
